using JT808Protocol.Abstracts;
using JT808Protocol.Models;
using SuperSocket.ProtoBase;
using System.Buffers;

namespace JT808Gateway
{
    public class JT808PackageFilter : BeginEndMarkPipelineFilter<JT808Package>
    {
        private IJT808Parser _serializer = new SuperSocketFilterJT808Parser();

        /// <summary>
        /// 部标数据包头尾标识
        /// </summary>
        private static byte[] BeginEndFlag => new byte[] { 0x7E };

        public JT808PackageFilter()
            : base(BeginEndFlag, BeginEndFlag)
        { }

        protected override JT808Package DecodePackage(ref ReadOnlySequence<byte> buffer)
        {
            var package = _serializer?.Parse(buffer.FirstSpan);
            return package;
        }
    }
}